#include "qtimeediteditor.h"

#include "../property/qabstractproperty.h"

#include <QLayout>

QTimeEditEditor::QTimeEditEditor(QAbstractProperty *pro,QWidget *parent):
    QAbstractPropertyEditor(pro,parent),
    m_time_edit(new QTimeEdit(this))
{
    layout()->addWidget(m_time_edit);
    m_time_edit->setTime(pro->get_value().toTime());
    connect(m_time_edit,SIGNAL(timeChanged(QTime)),this,SLOT(value_changed()));
}

void QTimeEditEditor::value_changed()
{
    emit property_changed(m_time_edit->time());
}

void QTimeEditEditor::property_value_changed()
{
    m_time_edit->setTime(m_property->get_value().toTime());
}



QDateEditEditor::QDateEditEditor(QAbstractProperty *pro,QWidget *parent):
    QAbstractPropertyEditor(pro,parent),
    m_date_edit(new QDateEdit(this))
{
    layout()->addWidget(m_date_edit);
    m_date_edit->setDate(pro->get_value().toDate());
    connect(m_date_edit,SIGNAL(dateChanged(QDate)),this,SLOT(value_changed()));
}

void QDateEditEditor::value_changed()
{
    emit property_changed(m_date_edit->date());
}

void QDateEditEditor::property_value_changed()
{
    m_date_edit->setDate(m_property->get_value().toDate());
}




QDateTimeEditEditor::QDateTimeEditEditor(QAbstractProperty *pro,QWidget *parent):
    QAbstractPropertyEditor(pro,parent),
    m_datetime_edit(new QDateTimeEdit(this))
{
    layout()->addWidget(m_datetime_edit);
    m_datetime_edit->setDateTime(pro->get_value().toDateTime());
    connect(m_datetime_edit,SIGNAL(dateTimeChanged(QDateTime)),this,SLOT(value_changed()));
}

void QDateTimeEditEditor::value_changed()
{
    emit property_changed(m_datetime_edit->dateTime());
}

void QDateTimeEditEditor::property_value_changed()
{
    m_datetime_edit->setDateTime(m_property->get_value().toDateTime());
}


qRegisterPropertyEditor("DateTime",QDateTimeEditEditor)
qRegisterPropertyEditor("Time",QTimeEditEditor)
qRegisterPropertyEditor("Date",QDateEditEditor)
